<?php
/*
 * Template name: BuyProduct
 */
get_header();
?>
<section class="content" style="margin-top: -80px">
    <?php if (isset($_POST['product_id'])) $id_product_current = $_POST['product_id']; ?>
    <div class="container-2">
        <form action="#" method="post" name="from_buy" class="form-register" onsubmit="return check_buy_product();">
            <input type="hidden" name="send_buy" value="send_buy"/>
            <div class="one-third first">
                <h3>Nhập thông tin khách hàng</h3>
                <div class="registerbox">
                    <fieldset>
                        <div class="control-group">
                            <label class="control-label"><span class="red">*</span> Tên người mua:</label>
                            <div class="controls">
                                <input type="text" name="name" id="name"  class="input-xlarge">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><span class="red">*</span> Số điện thoại:</label>
                            <div class="controls">
                                <input type="text" name="phone" id="phone" class="input-xlarge">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><span class="red">*</span> Địa chỉ Email:</label>
                            <div class="controls">
                                <input type="text" name="email" id="email"  class="input-xlarge">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"><span class="red">*</span> Địa chỉ:</label>
                            <div class="controls">
                                <input type="text" name="address" id="address" class="input-xlarge">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label"> </label>
                            <div class="controls" style="float: right">
                                <input class="button fright" style="width: 130px;margin-right: 30px;margin-top:60px" type="submit" value="Gữi thông tin"   class="input-xlarge">
                            </div>
                        </div>
                    </fieldset>
                </div>
            </div>
            <div class="one-third01" >
                <?php
                //lấy sản phẩm liên quan
                $catarogy_current_id_array = $wpdb->get_row("SELECT slug FROM wp_terms,wp_term_relationships WHERE term_id=term_taxonomy_id AND object_id=" . $id_product_current);
                $myposts = my_product_with_categoty($id_product_current, $catarogy_current_id_array);
                foreach ($myposts as $post) : setup_postdata($post);
                    if (wpsc_the_product_id() != $id_product_current)
                        continue;
                    ?>
                    <div class="entry" style="width: 100% !important;">
                        <div class="da-thumbs" style="width: 100%">
                            <div class="div-related">
                                <img src="<?php echo wpsc_the_product_thumbnail(); ?>" alt="">
                            </div>
                        </div>
                        <div style="margin-left: 50px">
                        <h3>
                            <a href="<?php echo $post->guid; ?>">
                                <?php echo wpsc_the_product_title(); ?>
                            </a>
                        </h3>
                        <span>
                            <small><?php
                                $price_o = wpsc_product_normal_price();
                               // echo substr($price_o, 0, -5);
                                ?>
                            </small>
                            Giá Sản Phẩm : 
                            <?php echo substr(wpsc_the_product_price(), 0, -5); ?>
                        </span> 
                        </div>
                    </div>      
                    <?php
                    //the end lấy sản phẩm 
                endforeach;
                ?>
            </div>
        </form>
    </div>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<script>
$(document).ready(function(){
    
});
function check_buy_product(){
    var name=$("input[name=name]").val();
    var phone=$("input[name=phone]").val();
    var email=$("input[name=email]").val();
    var address=$("input[name=address]").val();
    if(name==""){
        alert("bạn chưa nhập!");
        $("input[name=name]").focus();
        return false;
    }
    if(phone==""){
        alert("bạn chưa nhập!");
        $("input[name=phone]").focus();
        return false;
    }
    if(email=="" || checkEmail(email)==false){
        alert("bạn nhập địa chỉ mail chưa đúng!");
        $("input[name=email]").focus();
        return false;
    }
    if(address==""){
        alert("bạn chưa nhập!");
        $("input[name=address]").focus();
        return false;
    }
    
    
}
function checkEmail(email) {

    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (!filter.test(email.value)) {
    email.focus;
    return false;
 }}
</script>